package com.zxjbyte.yiyi.framework.tenant.aspect;

import com.zxjbyte.yiyi.framework.tenant.context.YiyiTenantContextHolder;
import com.zxjbyte.yiyi.framework.tenant.annotation.TenantIgnore;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;

/**
 * 自定义租户切面
 * @Author zhangxingjia
 * @Date 2023/3/14 11:45
 * @Version: 1.0
 */
@Aspect
public class YiyiTenantAspect {

    @Around("@annotation(tenantIgnore)")
    public Object around(ProceedingJoinPoint point, TenantIgnore tenantIgnore) throws Throwable {
        try {
            //开启忽略
            YiyiTenantContextHolder.setIgnore(Boolean.TRUE);
            //执行方法
            return point.proceed();
        } finally {
            //关闭忽略
            YiyiTenantContextHolder.clear();
        }
    }
}
